//当前页码
var nowPage = 1;
var totalPage = 1;
var moreAreaInfo = [];
var resourceArr = {};
var nowAreaPos = null;
var tagNo = 1;
//当前区域保存的模板信息
var nowPageArea = []
    // 当前焦点区域数据详情
var nowAreaZone = [];
//记录当前选中checkbox的数据详情
var nowAreaSelsChec = [];
var TemplateDetailsId = getUrlParam('templateDetailsId') //模板详情列表ID
    // 数据填充表格
var secondTable;
// $('.page-span').html(nowPage)

var nowShowTag; //填入数据数量说明

//当前栏目列表信息
var collist1 = { "id": null, "title": null, "name": null };
//当前栏目信息
var collist2 = { "id": null, "title": null, "name": null };
var collist3 = { "id": null, "title": null, "name": null };

// 对当前模板标记
resourceArr.home_type = "5";

// 初始化列表
initCollist();
$('#table_secondbox').hide();


var divs = ["AREA005x1x0y0", "AREA005x1x0y1", "AREA005x1x1"];

// 防止csrf
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

window.OPTIONS = {
    "AREA005x1x0y0": {
        "count": 1, // 资源个数
        "area": "x0y0",
        "areaType": "area",
        "areaId": "005"
    },
    "AREA005x1x0y1": {
        "count": 2, // 资源个数
        "area": "x0y1",
        "areaType": "area",
        "areaId": "005"
    },
    "AREA005x1x1": {
        "count": 6, // 资源个数
        "area": "x1",
        "areaType": "area",
        "areaId": "005"
    }
};

// 是否预览模板 --- 不能进行编辑
var onlineStatus = getUrlParam('online_status');
$(function() {
    if (onlineStatus == 1) {
        $('.table-itemSelsbox').hide();
        $('.uploadPicBtn').hide();
        // console.log('hide')
        return false;
    }
    // 给需要编辑的区域绑定点击事件
    $.each(divs, function(index, item) {
        $('#AREA005').on('click', '#' + item, function(e) {
            var option = window.OPTIONS[item];
            // 记录下现在是编写那块区域的数据
            store.set('current_area', item);
            $('.nowAreaDetail').hide();

            // 判断是否有活动焦点的类名(高亮标记保持为1个)
            if ($('.activefocus') && $('.activefocus').length != 0) {
                // console.log('remove')
                $('div.activefocus').removeClass('activefocus')
            }

            $(this).addClass('activefocus')

            // 设置当前区域信息
            nowAreaPos = item;
            resourceArr.area_no = item;
            resourceArr.template_type = window.OPTIONS[item].areaType
            resourceArr.template_no = window.OPTIONS[item].areaId
            resourceArr.zoneId = window.OPTIONS[item].area
            window.OPTIONS[nowAreaPos].resourceType = '5'


            nowAreaSelsChec = []; //当前选中的区域信息数据组

            var nowShowTagDetail = '当前区域 ' + item + ' 的数据详情';
            $('.nowAreaDetail .ibox-title h5').text(nowShowTagDetail)
            if (e.target.className.indexOf('uploadPicBtn') > 0) {
                $('#impic_upload').click();
                return false;
            }

            //填充详情表格数据信息
            // console.log(nowPageArea)     


            if (item != 'AREA005x1x1') {
                nowShowTag = '需填入数据数量：' + window.OPTIONS[item].count + '  |  数据类型为：' + collist1.name + '  |  当前区域为：' + item;
                secondTable.column(5).visible(false);
            } else {
                operateArea005x1x1(item);
            }
            $('#table_secondbox .ibox-title h5').text(nowShowTag)


            // 初始化判断是否有数据，解决左侧模版切换当前区域依旧有数据的问题

            //当前选择的详细信息填充
            fillNowDetailInfo(item);
            $('#table_secondbox').show();
        });
     
    });
})


/**
 * 当前选择的详细信息数据填充
 * 
 * @param {any} item [区域id]
 * @returns 
 */
function fillNowDetailInfo(item) {
    var nowAreaHasInfo = false;
    // console.log(item)
    console.log(nowPageArea)
    for (var i in nowPageArea) {
          // console.log(i)
          // console.log(nowPageArea[i].zoneId)
          // console.log(nowPageArea[i])

        if (item == String(nowPageArea[i].zoneId)) {
            if (item == 'AREA005x1x1') {
                // console.log('area005x1x1填充')
                nowAreaHasInfo = true;
                if (nowPage != 1) {
                    fillDetailSpecialTable(window.OPTIONS['AREA005x1x1'])
                }
                fillDetailSpecialTable(nowPageArea[i].resourceInfo)


                // fillDetailSpecialTable(window.OPTIONS['AREA005x1x1']);
                return;
            }
            nowAreaHasInfo = true;
            fillDetailTable(nowPageArea[i].resourceInfo)
            return;
        }
        // console.log(nowPageArea, i)
    }
    if (!nowAreaHasInfo) {
        fillDetailTable(null)
        fillDetailSpecialTable(null)
    }
    // console.log("当前初始化是否有数据:", nowAreaHasInfo)
}

/**
 * 特殊区域operateArea005x1x1相关操作
 * 
 */
function operateArea005x1x1(item) {
    // console.log('特殊区域填充数据 nowPageArea: ', nowPageArea)
    nowShowTag = '需填入数据数量：>' + window.OPTIONS[item].count + '  |  数据类型为：' + collist1.name + '  |  当前区域：' + item + '可分页';
    secondTable.column(5).visible(true);
    // fillNowDetailInfo('AREA005x1x1')
}

//左侧区域使用的table
detailTable = $('#table_detail').DataTable({
    // "processing": true,
    // 服务器端渲染
    // "serverSide": true,
    columns: [{
        title: '序号',
        orderable: false,
        data: null,
        width: "120px"
    }, {
        // 列名
        title: "编号",
        // 数据
        data: null,
        // 能否进行排序
        orderable: false,
        width: "*"
    }, {
        // 列名
        title: "名称",
        // 数据
        data: null,
        // 能否进行排序
        orderable: false,
        width: "*"
    }, {
        title: "标题",
        data: null,
        orderable: false,
        width: "*"
    }, {
        title: "操作",
        data: null,
        orderable: false,
        width: "*"
    }],
    "pagingType": "full_numbers",
    "sLoadingRecords": "正在加载数据...",
    "sZeroRecords": "暂无数据",
    // 能否进行搜索
    "searching": false,
    // "order": [[ 1, "asc" ]],
    "dom": '',
    "language": {
        "processing": "玩命加载中...",
        "lengthMenu": "显示 _MENU_ 项结果",
        "zeroRecords": "没有匹配结果",
        "info": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
        "infoEmpty": "显示第 0 至 0 项结果，共 0 项",
        "infoFiltered": "(由 _MAX_ 项结果过滤)",
        "infoPostFix": "",
        "url": "",
        "paginate": {
            "first": "首页",
            "previous": "上一页",
            "next": "下一页",
            "last": "末页"
        }
    },
});

$('#table_detail_special .pagination').on('click', '.pagination_l', function() {
    $('#AREA005x0').trigger('click');
})
$('#table_detail_special .pagination').on('click', '.pagination_r', function() {
    $('#AREA005x2').trigger('click');
})
$('#table_detail_special .pagination').on('click', '.pagelists a', function() {
    nowPage = $(this).text();
    $('.pagelists').eq(nowPage).addClass('active').siblings().removeClass('active')
    if (nowPage == 1) {
        $('#AREA005x1').show();
        $('#LISTx1').hide();
    } else {
        $('#AREA005x1').hide();
        $('#LISTx1').show();
    }
    fillNowPageArea5()
})

$('#AREA005x2').on('click', function() {

    // console.log('切换为列表模版')
    if (nowPage >= totalPage) {
        // console.log('无法翻页')
        return;
    } else {
        $('#LISTx1').empty();
        nowPage++;
        // console.log('翻页+1')
        $('#AREA005x1').hide();
        $('#LISTx1').show();
        // console.log(moreAreaInfo)
        fillNowPageArea5(nowPage)

    }
    $('.pagelists').eq(nowPage).addClass('active').siblings().removeClass('active')
})

$('#AREA005x0').on('click', function() {

    // console.log('切换为列表模版')
    if (nowPage == 1) {
        // console.log('无法翻页')
        return;

    } else {
        nowPage--;

        if (nowPage == 1) {
            $('#AREA005x1').show();
            $('#LISTx1').hide();

        } else {
            $('#LISTx1').empty();
            // console.log('翻页+1')
            $('#AREA005x1').hide();
            $('#LISTx1').show();
        }

        fillNowPageArea5(nowPage)
    }
    $('.pagelists').eq(nowPage).addClass('active').siblings().removeClass('active')
})

$('#table_secondbox').on('click', '.table-check-all', function() {

    changeAllCheck('second', $(this), $(this).is(':checked'))
})

$('#secondMenu1 .dropdown-menu').on('click', 'a', function() {
    var ind = $(this).parents().index();
    renderCollist1(ind);
    getCollist2(collist1.id);
})
$('#secondMenu2 .dropdown-menu').on('click', 'a', function() {
    var ind = $(this).parents().index();
    renderCollist2(ind);
    getCollist3(collist2.id);
})
$('#p1y2x0ul').on('click', 'li', function() {

    var ind = $(this).index();
    if ($('#AREA005x1').css("display") == "none") {
        $('#AREA005x1').show();
        $('#LISTx1').hide();
    }
    // newPageAreaChange();
    renderCollist3(ind)
    getColumns()
    nowPage = 1;

})

function initCollist() {
    getCollist1()
}
// 获取栏目列表信息
function getCollist1() {
    $.ajax({
        url: "/collists",
        type: "get",
        async: true,
        success: function(data) {
            if (data.status == 'success') {
                // console.log(data + '----getCollist1')

                $.each(data.content, function(ind, ele) {
                    $('#secondMenu1 .dropdown-menu').append('<li><a role="menuitem" tabindex="-1" href="javascript:;" data-id="' + ele.id + '" data-title="' + ele.title + '" data-name="' + ele.name + '">' + ele.name + '</a></li>')
                })
                renderCollist1(0)
                getCollist2(collist1.id)
            } else {
                layer.msg(data.content, {
                    icon: 5
                })

            }
        },
        error: function(data) {
            layer.msg("请求数据出错")
        }
    })
}
// 获取栏目下列表信息
function getCollist2(collistId) {
    $('#secondMenu2 .dropdown-menu').empty()

    $.ajax({
        url: "/collists/" + collistId + "/columns",
        type: "get",
        async: true,
        success: function(data) {
            if (data.status == 'success') {
                // console.log(data + '----getCollist2')
                $.each(data.content, function(ind, ele) {
                    $('#secondMenu2 .dropdown-menu').append('<li><a role="menuitem" tabindex="-1" href="javascript:;" data-id="' + ele.id + '" data-title="' + ele.title + '" data-name="' + ele.name + '">' + ele.name + '</a></li>')
                })
                renderCollist2(0);
                getCollist3(collist2.id);
            } else {
                layer.msg(data.content, {
                    icon: 5
                });
            }
        },
        error: function(data) {
            layer.msg("请求数据出错");

        }
    })
}
// 获取栏目下列表2级数据
function getCollist3(collistId) {
    $('#p1y2x0ul').empty();
    if (!collistId) {
        $('#p1y2x1').hide();
    } else {
        $('#p1y2x1').show();
    }

    $.ajax({
        url: "/columns/" + collistId + "/subcolumns",
        type: "get",
        async: true,
        success: function(data) {
            if (data.status == 'success') {
                // console.log(data, '----getCollist3')
                $.each(data.content, function(ind, ele) {
                    $('#p1y2x0ul').append('<li data-id="' + ele.id + '" data-title="' + ele.title + '" data-name="' + ele.name + '">' + ele.name + '</li>')
                })
                renderCollist3(0);
                getColumns()
            } else {
                layer.msg(data.content, {
                    icon: 5
                })
            }
        },
        error: function(data) {
            layer.msg("请求数据出错", {
                icon: 5
            })

        }
    })
}
// 渲染列表
function renderCollist1(ind) {
    collist1.title = $('#secondMenu1 .dropdown-menu li:eq(' + ind + ') a').attr("data-title");
    collist1.id = $('#secondMenu1 .dropdown-menu li:eq(' + ind + ') a').attr("data-id");
    collist1.name = $('#secondMenu1 .dropdown-menu li:eq(' + ind + ') a').attr("data-name");
    $('#secondLevelMenu1').html(collist1.name + '<i class="caret"></i>');
}

function renderCollist2(ind) {
    collist2.title = $('#secondMenu2 .dropdown-menu li:eq(' + ind + ') a').attr("data-title");
    collist2.id = $('#secondMenu2 .dropdown-menu li:eq(' + ind + ') a').attr("data-id");
    collist2.name = $('#secondMenu2 .dropdown-menu li:eq(' + ind + ') a').attr("data-name");
    $('#secondLevelMenu2').html(collist2.name + '<i class="caret"></i>');
}

function renderCollist3(ind) {
    collist3.title = $('#p1y2x0ul li:eq(' + ind + ')').attr("data-title");
    collist3.id = $('#p1y2x0ul li:eq(' + ind + ')').attr("data-id");
    collist3.name = $('#p1y2x0ul li:eq(' + ind + ')').attr("data-name");
    $('#p1y2x0ul li').eq(ind).addClass("heightLight").siblings().removeClass('heightLight');
}
// 渲染当前模版
function getColumns() {
    // console.log(collist3.id)
    if (collist3.id) {
        $('#p1y2x1').css("display", "block")
    } else {
        $('#p1y2x1').css("display", "none")
    }
    /* 判断是否第一次加载表格 */
    if (!secondTable) {
        renderSecendTable();
    } else {
        refreshDataTable()
        $('#table_secondbox').hide();
        $('.nowAreaDetail').hide();
    }
    $('.activefocus').removeClass('activefocus')
    $('.table-check-all').prop('checked', false)
        //newPageAreaChange()
    fillNowPageArea5()
    if ($('#AREA005x1').css("display") == "none") {
        $('#AREA005x1').show();
        $('#LISTx1').hide();
    }
}
/**
 * renderSecendTable 渲染数据列表表格
 */
function renderSecendTable() {
    if (!collist3.id) {
        return;
    }
    secondTable = $('#table_second').DataTable({
        // "processing": true,
        // 服务器端渲染/*  */
        "serverSide": true,
        // 请求数据的形式(get, post), 请求的路径
        ajax: {
            // 数据的url
            url: "/subcolumns/" + collist3.id + "/vassetis",
            type: "POST",
            data: function(d) {
                d.collist = collist1.id;
                d.column = collist2.id;
                d.subcolumn = collist3.id;
                d.templateDetailsId = TemplateDetailsId,
                    // 归类
                    // d.vcat = $('#table-point-search1').val();
                    // 分类
                    // d.vcattag = $('#table-point-search2').val();
                    // 搜索框
                    d.search_value = $('#table-second-search-inp').val();

            },
        },
        columns: [{
            orderable: false,
            data: "id",
            title: '<input class="table-check-all"  name="check-all" type="checkbox" value=""/>全选/反选',
            render: function(id) {
                return '<input type="checkbox" data-vassetiId="' + id + '" name="checkbox-second">'
            },
            width: "150px"
        }, {
            title: "排序",
            data: null,
            orderable: true,
            width: "*"
        }, {
            title: "编号",
            data: "vasseti_id",
            orderable: true,
            width: "*"
        }, {
            title: "名称",
            data: "vasseti.name",
            orderable: true,
            width: "*"
        }, {
            title: "标题",
            data: "vasseti.title",
            orderable: true,
            width: "*"
        }, {
            orderable: false,
            data: null,
            title: '操作',
            render: function(id) {
                return '<button class="btn btn-sm btn-primary\
                  saveOneBtn" type="button">\
                    添加\
                </button>'
            },
            width: "100px",
        }, ],
        // 分页类型
        "pagingType": "full_numbers",
        "sLoadingRecords": "正在加载数据...",
        "sZeroRecords": "暂无数据",
        // 能否进行搜索
        "searching": false,
        "destroy": true,
        "order": [
            [1, "asc"]
        ],
        "dom": 'rt<"bottom"ilp<"clear">>',
        "language": {
            "processing": "玩命加载中...",
            "lengthMenu": "显示 _MENU_ 项结果",
            "zeroRecords": "没有匹配结果",
            "info": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
            "infoEmpty": "显示第 0 至 0 项结果，共 0 项",
            "infoFiltered": "(由 _MAX_ 项结果过滤)",
            "infoPostFix": "",
            "url": "",
            "paginate": {
                "first": "首页",
                "previous": "上一页",
                "next": "下一页",
                "last": "末页"
            }
        },
        fnDrawCallback: function() {　　
            var api = this.api();　　
            api.column(1).nodes().each(function(cell, i) {　　　　
                cell.innerHTML = i + 1;　　
            });
        },
        _fnPageChange: function() {}
    });
}

/**
 * [fillNowPageArea5 初始化页面回填数据]
 * @param  {[type]} page [页码]
 * @return {[type]}      [description]
 */
function fillNowPageArea5(page, nowZone, callback) {
    var shortPostJson = {
        "template_type": "AREA",
        "template_no": "005",
        "collist_id": collist1.id,
        "column_id": collist2.id,
        "subcolumn_id": collist3.id,
        "page": nowPage,
        "limit": 12,
        "templateDetailsId": TemplateDetailsId
    }
    $.ajax({
        url: "/template_type/data/area/subcolumn/backfill",
        type: "post",
        // async: true,
        timeout: 5000,
        data: shortPostJson,
        success: function(data) {
            // console.log('backfill-----------')
            nowAreaSelsChec = [];
            totalPage = data.content.total;
            // nowPageArea = [];
            console.log(data);
            if (data.status == 'success') {
                var contentTempNo = data.content.template_datas
                var shortTag = false;
                $('.page-span').html(nowPage + '/' + totalPage)

                if (!contentTempNo) {
                    nowPageArea = null;
                    // return;
                }
                getPaginationDetial()
                    // 渲染模板区域的数据信息
                renderBackfillOptions(contentTempNo);
                // console.log(nowZone)
                if (nowZone) {
                    if (nowZone == 'AREA005x1x1') {
                        // fillDetailSpecialTable(nowPageArea[i].resourceInfo)
                        fillNowDetailInfo('AREA005x1x1')
                    }
                }

                if (callback) {
                    callback();
                }
            } else {
                 newPageAreaChange()
                 $('#table_detail_special tbody').empty();
                 nowPageArea = [];
                 console.log(window.OPTIONS[nowAreaPos]);
                 if(window.OPTIONS[nowAreaPos]){
                    window.OPTIONS[nowAreaPos].resourceInfo = [];
                 }
                 
            }
        },
        error: function(data) {
            layer.msg("数据请求出错", {
                icon: 5
            })
        }
    })
}


/**
 * getPaginationDetial 获取页码信息
 * 全局参数 ： totalPage nowPage
 */
function getPaginationDetial() {
    // console.log('getPagination')
    var patinationDetial = '<li><a href="javascript:;" class="pagination_l">&lt;</a></li>'
    var paginationList = '';
    for (var i = 1; i <= totalPage; i++) {
        if (i == nowPage) {
            paginationList += '<li class="pagelists"><a href="javascript:;" class="active">' + i + '</a></li>'
        } else {
            paginationList += '<li class="pagelists"><a href="javascript:;">' + i + '</a></li>'
        }
    }
    patinationDetial += paginationList + '<li><a href="javascript:;" class="pagination_r">&gt;</a></li>'
    $('#table_detail_special .pagination').html(patinationDetial)
}



/**
 * 重新绘制模板区域
 * 
 * @param {any} contentTempNo [传入的模板区域数据]
 */
function renderBackfillOptions(contentTempNo) {
    // console.log('area renderBackfillOption nowAreapos:', nowAreaPos, 'nowPage', nowPage, "window.OPTIONS['AREA005x1x1']:", window.OPTIONS['AREA005x1x1'])
        //对area5区域默认填充

    if (nowAreaPos == 'AREA005x1x1' && nowPage != 1) {

        if (contentTempNo['AREA005x1x1']) {
            $('#AREA005x1').hide();
            $('#LISTx1').show();
            window.OPTIONS['AREA005x1x1'].resourceInfo = contentTempNo['AREA005x1x1']
            $('#LISTx1').empty();
            $.each(contentTempNo.AREA005x1x1, function(index, item) {
                $('#LISTx1').append('<li class="ver-box-style"><img src="' + item.img + '"><p>' + item.title + '</p></li>')
            })
        }
        recordNowData('AREA005x1x1')
        fillNowDetailInfo('AREA005x1x1')
    } else {

        newPageAreaChange();
        for (var i in window.OPTIONS) {
            var shortFlag = true;
            var short_nowDiv = $('#' + i)
            for (var areaItem in contentTempNo) {
                if (i == areaItem) {
                    shortFlag = false;

                    // 填充当前区域
                    window.OPTIONS[i].resourceInfo = contentTempNo[i]
                        // 判断是否为列表数据
                    // console.log(contentTempNo[i])
                    if (!contentTempNo[i].length) {
                        continue;
                    }
                    if (short_nowDiv.find('li').length >= 1) {
                        $.each(short_nowDiv.find('li'), function(index, item) {

                            // console.log(item)
                            //    console.log(contentTempNo[i][index])
                            if (!contentTempNo[i][index]) {

                                return;
                            }
                            $(item).find('p').html(contentTempNo[i][index].title);
                            $(item).find('img').attr({
                                'src': contentTempNo[i][index].img
                            });
                        })
                    } else {
                        short_nowDiv.find('p').html(contentTempNo[i][0].title);
                        short_nowDiv.find('img').attr({
                            'src': contentTempNo[i][0].img
                        });
                    }


                }
            }
            // console.log(window.OPTIONS)
                //  当前区域没有数据信息
            if (shortFlag) {
                window.OPTIONS[i].resourceInfo = null;

                //    if (!contentTempNo[i].length) continue;  ???

                renderZoneNoneData(short_nowDiv)

            }
            //  记录当前页面区域信息
            recordNowData(i)
            if (nowAreaPos == 'AREA005x1x1') {
                fillNowDetailInfo('AREA005x1x1')
            }
        }
    }



}

/**
 * [recordNowData 记录当前页面区域信息]
 * 
 * @param {当前区域id} nowZoneId 
 */
function recordNowData(nowZoneId) {
    // 判断nowPageArea中是否有数据
    // 有 则判断是否有当前区域id信息，替换
    // 没有 则追加当前区域信息
    // console.log(nowPageArea)
    if (!nowPageArea || !nowPageArea.length) {
        nowPageArea = [];
        nowPageArea.push({
            "zoneId": nowZoneId,
            "resourceInfo": window.OPTIONS[nowZoneId].resourceInfo
        })
    } else {
        var flag = false;
        $.each(nowPageArea, function(ind, ele) {
            if (ele['zoneId'] == nowZoneId) {
                flag = true;
                ele['resourceInfo'] = window.OPTIONS[nowZoneId].resourceInfo
            }
        })
        if (!flag) {
            nowPageArea.push({
                "zoneId": nowZoneId,
                "resourceInfo": window.OPTIONS[nowZoneId].resourceInfo
            })
        }
    }
    // console.log('当前页面区域信息', 'nowPagearea=', nowPageArea)
}

/**
 * [renderZoneNoneData 渲染当前没有数据的区域为默认区域]
 * 
 * @param {没有数据的区域id} short_nowDiv 
 */
function renderZoneNoneData(short_nowDiv) {
    if (short_nowDiv.find('li').length >= 1) {
        $.each(short_nowDiv.find('li'), function(index, item) {

            $(item).find('p').html("占位文字");
            $(item).find('img').attr({
                'src': "/custom-templates/images/defaultImg2.png"
            });
        })
    } else {
        short_nowDiv.find('p').html("占位文字");
        short_nowDiv.find('img').attr({
            'src': "/custom-templates/images/defaultImg2.png"
        });
    }
}

//保存已选择数据
function saveArea5Data(resourceArr, one) {
    // let _collist_type = (collist1.id == 1||collist1.id==2)?collist1.id:""
    var shortPostJson = {
        "template_type": resourceArr.template_type,
        "template_no": resourceArr.template_no,
        "resource_type": resourceArr.resource_type,
        "area_no": resourceArr.area_no,
        "resource_id": resourceArr.resource_id,
        "home_type": resourceArr.home_type,
        "collist_id": collist1.id,
        "column_id": collist2.id,
        "subcolumn_id": collist3.id,
        "vasseti_id": resourceArr.resource_id,
        "templateDetailsId": TemplateDetailsId,
        // "type":collist1.id
    }
    // console.log(shortPostJson)
    $.ajax({
        url: "/template_type/data/subcolumn/save",
        type: "post",
        data: shortPostJson,
        success: function(data) {
            if (data.status == 'success') {
                layer.msg(data.content, {
                    icon: 1
                });
                // 判断当前区域是否为'AREA005x1x1'
                //     是：
                //     不是：
                if (nowAreaPos == 'AREA005x1x1') {
                    // fillDetailSpecialTable(nowAreaSelsChec, true)
                    fillNowPageArea5()
                } else {
                    $('.table-itemSelsbox').hide();
                    // window.OPTIONS[nowAreaPos].resourceInfo = nowAreaSelsChec;
                    fillNowPageArea5(null, null, function() {
                        fillDetailTable(window.OPTIONS[nowAreaPos].resourceInfo);
                    })

                }
                $('.table-check-all').prop('checked', false);
                refreshDataTable()
            } else {
                layer.msg(data.content, {
                    icon: 5
                })
            }

        },
        error: function(data) {
            layer.msg("数据保存出错", {
                icon: 5
            })
        }
    })
}
// 选择的区域模版焦点操作
$('.removeFocus').on('click', function() {
    $('#' + nowAreaPos).removeClass('activefocus')
})

// 回退按钮
$('.table-back-btn').on('click', function() {
    history.go(-1)
        /* var locat = String(location.href)
        var locaArr = locat.split("/");
        var nowLocation = '';
        for (var i in locaArr) {
            nowLocation += locaArr[i] + '/';
            if (locaArr[i] == 'admin') {
                nowLocation += 'operation/content_templates'
                location.href = nowLocation;
                return;
            }
        } */
})

/**
 * 提交保存当前数据信息
 */
$('.savebtn').on('click', function() {
        var _this = this
        var short_resource_id = []
        if (nowAreaPos != 'AREA005x1x1' && nowAreaSelsChec.length != window.OPTIONS[nowAreaPos].count) {
            layer.msg('填入数据个数不符,请选择 ' + window.OPTIONS[nowAreaPos].count + ' 个数据', {
                icon: 5
            });
            return;
        } else {
            $(nowAreaSelsChec).each(function(ind, ele) {
                short_resource_id.push({
                    "id": ele.id
                })
            })
            resourceArr.resource_id = short_resource_id;
            resourceArr.resource_type = "1"
            resourceArr.templateDetailsId = TemplateDetailsId;
            saveArea5Data(resourceArr)
        }
    })
    /*
     * 单个按钮添加
     */
$('#table_secondbox').on('click', '.saveOneBtn', function() {
    var ind = $(this).index();
    nowAreaSelsChec = [];
    setNowAreaZone(null, $(this), "check")

    var short_resource_id = []
    $(nowAreaSelsChec).each(function(ind, ele) {
        short_resource_id.push({
            "id": ele.id
        })
    })
    resourceArr.resource_id = short_resource_id;
    resourceArr.resource_type = "1"
    saveArea5Data(resourceArr, 'one')
})


$('#table_secondbox').on("click", 'tr input[name="checkbox-second"]', function() {
    tableDetailChange('second', $(this))
});

//删除已添加媒资
$('.areaDetail').on('click', 'th.trashBtn', function(e) {
    var nowInd = $(e.target).parents('tr').index()
    layer.msg('确定要删除?', {
        time: 0, //不自动关闭,
        btn: ['确定', '取消'],
        yes: function(index) {
            layer.close(index);
            var shortVassetiId = []
                //右侧
            if (nowAreaPos == 'AREA005x1x1') {
                var shortVassetId = $('#table_detail_special th[name=tagDetailVassetiId]').index();
                var indTagId = $('#table_detail_special tbody tr').eq(nowInd).find('th').eq(shortVassetId).text();
                shortVassetiId.push(indTagId)
                // console.log(shortVassetiId, ' shortVassetiId')
            } else {
                //左侧
                // console.log(window.OPTIONS[nowAreaPos].resourceInfo)
                $.each(window.OPTIONS[nowAreaPos].resourceInfo, function(i, delArea) {
                    shortVassetiId.push(delArea.id)
                })
            }
            var shortPostJson = {
                "template_type": "AREA",
                "template_no": 1,
                "area_no": nowAreaPos,
                "collist_id": collist1.id,
                "column_id": collist2.id,
                "subcolumn_id": collist3.id,
                "vasseti_id": shortVassetiId,
                "templateDetailsId": TemplateDetailsId,
                "templateDetailsId": TemplateDetailsId
            }
            // console.log(shortPostJson)
            $.ajax({
                url: '/template_type/data/area/subcolumn/delete',
                type: 'POST',
                cache: false,
                dataType: 'json',
                data: shortPostJson,
                success: function(data) {
                    if (data.status == 'success') {
                        layer.alert(data.content, {
                            icon: 1
                        });
                        if (nowAreaPos == 'AREA005x1x1') {
                            $(e.target).parents('tr').remove()
                        } else {
                            $('#table_detail tbody').empty();
                        }
                        // debugger;
                        // alert(1);
                        fillNowPageArea5(null, nowAreaPos, function() {
                            fillDetailTable(window.OPTIONS[nowAreaPos].resourceInfo)
                            // console.log(window.OPTIONS[nowAreaPos].resourceInfo)
                            refreshDataTable()
                        })

                    } else {
                        layer.msg(data.content, {
                            icon: 2
                        });
                    }
                },
                error: function() {
                    layer.msg("删除失败", {
                        icon: 5
                    });
                }
            });
        }
    })
});

/* 更改当前模板数据信息 */
$('.detailChangeBtn').on('click', function(ind, item) {

        $('#table_secondbox').show();
        refreshDataTable()
    })
    /* 搜索按钮操作 */
$('.tables-select-search').on('click', function() {
    refreshDataTable()
})

function refreshDataTable() {
    secondTable.ajax.url("/subcolumns/" + collist3.id + "/vassetis").load();
    nowAreaSelsChec = [];
}

/**
 * [tableDetailChange 对checkbox选择动态渲染]
 * @param  {[type]} nowDiv      [当前模板关联选择 subject/live/collist]
 * @param  {[type]} nowCheckbox [当前点击的checkbox框]
 */
function tableDetailChange(nowDiv, nowCheckbox) {
    //选中状态事件处理
    var nowZoneInfo = {} //向后台传递的数据
    var nowZoneInfoArr = []
    var nowAreaZone = [] //当前区域记录的数据详细信息 
    $('#table_' + nowDiv + 'box').find('.table-check-all').prop('checked', false);
    if ($('#' + nowAreaPos).find('li').length >= 1 && nowAreaPos != 'AREA005x1x1') {
        if ($('#table_' + nowDiv + 'box input[name="checkbox-' + nowDiv + '"]:checked').length > window.OPTIONS[nowAreaPos].count) {
            layer.msg('请选择' + window.OPTIONS[nowAreaPos].count + '个数据！', {
                icon: 5
            });
            nowCheckbox.prop('checked', false);
        }
        //
        if (!nowCheckbox.is(':checked')) {
            renderZoneNoneData($('#' + nowAreaPos))
                /* $.each($('#' + nowAreaPos).find('li'), function(index, item) {
                    $(item).find('p').html('占位符')
                    $(item).find('img').attr({
                        'src': '/custom-templates/images/defaultImg2.png',
                        'alt': "图片占位"
                    })
                }) */
            setNowAreaZone(nowDiv, nowCheckbox, 'cancel')

        } else {
            // 选中当前checkbox框
            setNowAreaZone(nowDiv, nowCheckbox, 'check')
        }
        // console.log(nowAreaSelsChec)
            // 判断是否满足需求的填入信息
        if ($('#table_' + nowDiv + 'box input[name="checkbox-' + nowDiv + '"]:checked').length == window.OPTIONS[nowAreaPos].count) {
            //是否全选？
            if ($('#table_' + nowDiv + 'box tbody input[name="checkbox-' + nowDiv + '"]').length == $('#table_' + nowDiv + 'box tbody input[name="checkbox-' + nowDiv + '"]:checked').length) {
                $('#table_' + nowDiv + 'box').find('.table-check-all').prop('checked', true);
            }

            // 记录当前区域信息
            $.each(nowAreaSelsChec, function(index, item) {
                nowZoneInfoArr.push({
                    "id": item.id
                })
            })
            nowZoneInfo.resource_id = nowZoneInfoArr;
            nowZoneInfo.resource_type = collist1.id
            getAreaZone(nowZoneInfo)
            // console.log(nowAreaSelsChec)
                // window.OPTIONS[nowAreaPos].resourceInfo = nowAreaSelsChec;
        }
        /* else if(nowAreaPos=='AREA005x1x1' && $('#table_' + nowDiv + 'box input[name="checkbox-' + nowDiv + '"]:checked').length >= window.OPTIONS[nowAreaPos].count){
             $.each(nowAreaSelsChec, function(index, item) {
                 nowZoneInfoArr.push({
                     "id": item.id
                 })
             })
             nowZoneInfo.resource_id = nowZoneInfoArr;
             nowZoneInfo.resource_type = collist1.id
             getAreaZone(nowZoneInfo)
             window.OPTIONS[nowAreaPos].resourceInfo = nowAreaSelsChec;
         }*/
    } else if (nowAreaPos == 'AREA005x1x1') {
        if (!nowCheckbox.is(':checked')) {
            setNowAreaZone(nowDiv, nowCheckbox, 'cancel')
            return;
        } else {
            // 选中当前checkbox框
            setNowAreaZone(nowDiv, nowCheckbox, 'check')
        }
        // console.log(nowAreaSelsChec)
        $.each(nowAreaSelsChec, function(index, item) {
            nowZoneInfoArr.push({
                "id": item.id
            })
        })
        nowZoneInfo.resource_id = nowZoneInfoArr;
        nowZoneInfo.resource_type = collist1.id
        getAreaZone(nowZoneInfo)
            //window.OPTIONS[nowAreaPos].resourceInfo = nowAreaSelsChec;
    } else {
        nowAreaSelsChec = []
        if ($('#table_' + nowDiv + 'box input[name="checkbox-' + nowDiv + '"]:checked').length > window.OPTIONS[nowAreaPos].count) {
            $('#table_' + nowDiv + 'box input[name="checkbox-' + nowDiv + '"]:checked').prop('checked', false)
            nowCheckbox.prop('checked', true);
        }
        // 选中状态变未选中状态 
        if (!nowCheckbox.is(':checked')) {
            /* $('#' + nowAreaPos).find('p').html('占位符')
            $('#' + nowAreaPos).find('img').attr({
                'src': '/custom-templates/images/defaultImg2.png',
                'alt': "图片占位"
            }) */
            renderZoneNoneData($('#' + nowAreaPos))
            setNowAreaZone(nowDiv, nowCheckbox, 'cancel')
            // console.log(nowAreaSelsChec)
            return;
        }
        nowZoneInfoArr.push({
            "id": nowCheckbox.parents('tr').find('td:eq(2)').html()
        })
        nowZoneInfo.resource_id = nowZoneInfoArr;
        nowZoneInfo.resource_type = collist1.id;
        nowZoneInfo.templateDetailsId = TemplateDetailsId;
        getAreaZone(nowZoneInfo)
        setNowAreaZone(nowDiv, nowCheckbox, 'check')
        // console.log(nowAreaSelsChec)
    }
}

function getAreaZone(nowZoneInfo) {
    $.ajax({
        url: "/template_type/data/infos",
        type: "get",
        data: nowZoneInfo,
        success: function(data) {
            var data = data.content
            $.each(data, function(zoneInd, zone) {
                if ($('#' + nowAreaPos).find('li').length >= 1) {
                     if (resourceArr.home_type == '5' && nowAreaPos == 'AREA005x1x1') {
                        //模版5特殊区域多项选择操作
                        if (zoneInd < window.OPTIONS[nowAreaPos].count) {
                            $('#' + nowAreaPos).find('li').eq(zoneInd).find('p').html(zone.title)
                            $('#' + nowAreaPos).find('li').eq(zoneInd).find('img').attr({
                                'src': zone.img
                            })
                        } else {}
                    } 
                    $('#' + nowAreaPos).find('li').eq(zoneInd).find('p').html(zone.title)
                    $('#' + nowAreaPos).find('li').eq(zoneInd).find('img').attr({
                        'src': zone.img
                    })
                } else {
                    $('#' + nowAreaPos).find('p').html(zone.title)
                    $('#' + nowAreaPos).find('img').attr({
                        'src': zone.img
                    })
                }
            })
        }
    })
}


/**
 * [fillDetailTable 填充当前页面详情表格数据]
 * @param  {[type]} data [需要填充的数据组]
 * @return {[type]} oneFlag [是否只添加一个数据]
 */
//右侧模板表格
function fillDetailTable(data, oneFlag) {
    $('.nowAreaDetail').hide();
    $('.tableSpecialdelAll').prop("checked", false)
    // console.log('nowAreaPos', nowAreaPos, 'data', data, 'window.OPTIONS[nowAreaPos]', window.OPTIONS[nowAreaPos])
    if (nowAreaPos == 'AREA005x1x1') {
        $('#table_detail_special').fadeIn(400)
    } else {
        $('#table_detail_common').fadeIn(400)
    }
    if (oneFlag) {
        $('#table_detail_common').fadeIn(400)
    } else {
        $('.nowAreaDetail .table tbody').empty();
    }
    var indLen = $('#table_detail_common tbody tr').length;
    // alert(window.OPTIONS[nowAreaPos].resourceInfo)
    // console.log('data', data)
    // console.log('window.OPTIONS[nowAreaPos].resourceInfo', window.OPTIONS[nowAreaPos].resourceInfo)
    // console.log(window.OPTIONS[nowAreaPos],'data',data);
    if(nowAreaPos== 'AREA005x1x1'){
        // console.log(window.OPTIONS[nowAreaPos],nowAreaPos,'右侧特殊区域')
        fillDetailSpecialTable(data)
        return;
    }
    if (window.OPTIONS[nowAreaPos].resourceInfo) {
        // console.log(window.OPTIONS[nowAreaPos].resourceInfo.length)
        if(window.OPTIONS[nowAreaPos].resourceInfo.length != 0){
           for (var i = 0; i < window.OPTIONS[nowAreaPos].count; i++) {
            //    console.log(typeof data[i]=="undefined")
               if(!data||!data[i]||typeof data[i] == "undefined") break;
                $('#table_detail_common .table tbody').append('<tr>\
                <th>' + (++indLen) + '</th>\
                <th>' + data[i].id + '</th>\
                <th>' + data[i].name + '</th>\
                <th>' + data[i].title + '</th>\
                <th class="trashBtn"><i class="glyphicon glyphicon-trash"></i></th>\
              </tr>');
            }
            
            refreshDataTable()
            return; 
        }
        
    } else {
        $('.nowAreaDetail').hide();
    }
    //有时会出现数据传递不正确的情况，显示确定的数量
    // if(window.OPTIONS[nowAreaPos].count != data.length){


    // }
    /*  $.each(data, function(ind, details) {
         // <th>' + details.resource_name + '</th>\
         $('#table_detail_common .table tbody').append('<tr>\
         <th>' + (++indLen) + '</th>\
         <th>' + details.id + '</th>\
         <th>' + details.name + '</th>\
         <th>' + details.title + '</th>\
         <th class="trashBtn"><i class="glyphicon glyphicon-trash"></i></th>\
       </tr>');
     })
     refreshDataTable() */
}

/**
 * 特殊区域数据填充操作
 * 
 * @param {any} data [需要填充的数据组]
 * @param {any} oneFlag [是否只添加一个数据] 
 */
function fillDetailSpecialTable(data, oneFlag) {
    $('.nowAreaDetail').hide();
    $('#table_detail_special').fadeIn(400);
    // if(oneFlag){
    // $('#table_detail_special').fadeIn(400)
    // }else{
    $('.nowAreaDetail .table tbody').empty();
    // }
    var IndDetailSort = $('#table_detail_special th[name=tagDetailSort]').index();
    var IndDetailVassetiId = $('#table_detail_special th[name=tagDetailVassetiId]').index();
    var IndDetailName = $('#table_detail_special th[name=tagDetailName]').index();
    var IndDetailTitle = $('#table_detail_special th[name=tagDetailTitle]').index();
    var IndDetailDone = $('#table_detail_special th[name=tagDetailDone]').index();

    var totalIndLen = $('#table_detail_special thead th').length;
    var indLen = $('#table_detail_special tbody tr').length;
    // console.log(data)
    $.each(data, function(ind, details) {
        // <th>' + details.resource_name + '</th>\

        $('#table_detail_special .table tbody').append('<tr>\
        <th><input class="table-special-one" name="specialCheck" type="checkbox" value=""></th>\
        <th>' + (++indLen) + '</th>\
        <th>' + details.id + '</th>\
        <th>' + details.name + '</th>\
        <th>' + details.title + '</th>\
        <th class="trashBtn"><i class="glyphicon glyphicon-trash"></i></th>\
      </tr>');
        console.log(specialChecks,'特殊区域数据填充操作')

        $.each(specialChecks, function(ele, j) {
            // console.log(j)
            if (details.id == j) {
                $('#table_detail_special .table tbody tr').eq(indLen - 1).find('.table-special-one').prop("checked", true)
            }
        })

        /* $.each($('#table_detail_special .table tbody tr'),function(ind,ele){
        for(var j in specialChecks){
                
            if($(ele).find('th').eq(IndDetailVassetiId).text() == j){
            $(ele).find('.table-special-one').attr({"checked":true})
            }
        }
        }) */

    })

    // secondTable.ajax.url("/subcolumns/"+collist3.id+"/vassetis").load();    
    refreshDataTable()
    // console.log("fill-special === 更新vassetis 清空nowAreaSelsChec")
}



/**
 * [全选/反选操作]
 * @param  {[type]} checkAllDiv [当前表格说明]
 */
function changeAllCheck(checkAllDiv, nowDiv, flag) {
    var flagCheck = 0;
    nowAreaSelsChec = []
    $('#table_' + checkAllDiv + ' tr input[type="checkbox"][name="checkbox-' + checkAllDiv + '"]').each(function(index, item) {
        if (flag) {
            if (nowAreaPos == 'AREA005x1x1') {
                $(item).prop("checked", true);
                flagCheck = 1;
                setNowAreaZone(null, $(item), 'check')
            } else if (nowAreaPos != 'AREA005x1x1' && window.OPTIONS[nowAreaPos].count == $('#table_' + checkAllDiv + 'box tr input[name="checkbox-' + checkAllDiv + '"]').length) {
                $(item).prop("checked", true);
                flagCheck = 1;
                setNowAreaZone(null, $(item), 'check')
            }
        } else {
            $(item).prop("checked", false);
            setNowAreaZone(null, $(item), 'cancel')
        }

    });
    /* if(flagCheck){
         fillListData(checkAllDiv)
        }*/
}
/* 修改记录：
   nowAreaZone 为选中的信息组
   设置 nowAreaSelsChec = [] 记录当前选中项
 */
/* 单击选中框操作 */
function setNowAreaZone(nowDiv, nowCheckbox, btnAttr) {
    var zonedataId = {}
    var shortZoneInfo = []
    // console.log('setNowAreaZone------', nowAreaSelsChec);
    if (btnAttr == 'check') {
        zonedataId.id = nowCheckbox.parents('tr').find('td').eq(2).html()
        zonedataId.name = nowCheckbox.parents('tr').find('td').eq(3).html()
        zonedataId.title = nowCheckbox.parents('tr').find('td:eq(4)').html()
        nowAreaSelsChec.push({
            "id": zonedataId.id,
            "resource_name": collist1.name,
            "name": zonedataId.name,
            "title": zonedataId.title
        })
    } else if (btnAttr == 'cancel') {
        $.each(nowAreaSelsChec, function(index, item) {
            if (!item) return;
            if (item.id == nowCheckbox.parents('tr').find('td').eq(2).html()) {
                nowAreaSelsChec.splice(index, 1);
                return;
            }
        })
    } else if (btnAttr == 'none') {
        nowAreaSelsChec = []
    }
}

// 刷新页面操作
function runRefresh() {
    secondTable.ajax.url("/subcolumns/" + collist3.id + "/vassetis").load()
    nowAreaSelsChec = [];
    specialChecks = [];
}

function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg); //匹配目标参数
    if (r != null) return unescape(r[2]);
    return null; //返回参数值
}

/**
 * newPageAreaChange 对AREA005x1默认填充
 * 
 */
function newPageAreaChange() {
    $('#AREA005x1').empty()
    var dom = '<div id="AREA005x1x0" style="">\
                <div class="ver-box-style" id="AREA005x1x0y0" tabindex="-1">'
    if (onlineStatus == 0) {
        dom += '<button class="btn btn-primary uploadPicBtn" type="submit">上传图片</button>';
    }
    dom += '<img src="/custom-templates/images/defaultImg2.png" alt=""><p class="style1-con-des">占位文字<span></span></p></div>\
                <div id="AREA005x1x0y1">\
                    <ul id="AREA005x1x0y1ul">\
                    <li class="ver-box-style"><img src="/custom-templates/images/defaultImg2.png"><p class="style1-con-des">占位文字<span style="padding-left:10px;"></span></p></li>\
                    <li class="ver-box-style"><img src="/custom-templates/images/defaultImg2.png"><p class="style1-con-des">占位文字<span style="padding-left:10px;"></span></p></li>\
                    </ul>\
                </div>\
                </div>\
                <div id="AREA005x1x1" style="">\
                    <ul id="AREA005x1x1ul">\
                    <li class="ver-box-style"><img src="/custom-templates/images/defaultImg2.png"><p class="style1-con-des">占位文字<span style="padding-left:10px;"></span></p></li>\
                    <li class="ver-box-style"><img src="/custom-templates/images/defaultImg2.png"><p class="style1-con-des">占位文字<span style="padding-left:10px;"></span></p></li>\
                    <li class="ver-box-style"><img src="/custom-templates/images/defaultImg2.png"><p class="style1-con-des">占位文字<span style="padding-left:10px;"></span></p></li>\
                    <li class="ver-box-style"><img src="/custom-templates/images/defaultImg2.png"><p class="style1-con-des">占位文字<span style="padding-left:10px;"></span></p></li>\
                    <li class="ver-box-style"><img src="/custom-templates/images/defaultImg2.png"><p class="style1-con-des">占位文字<span style="padding-left:10px;"></span></p></li>\
                    <li class="ver-box-style"><img src="/custom-templates/images/defaultImg2.png"><p class="style1-con-des">占位文字<span style="padding-left:10px;"></span></p></li>\
                    <li class="ver-box-style"><img src="/custom-templates/images/defaultImg2.png"><p class="style1-con-des">占位文字<span style="padding-left:10px;"></span></p></li>\
                    </ul>\
                </div>\
            </div>'
    $('#AREA005x1').html(dom)

}

/**
 * 全选删除按钮
 */
var specialChecks = [];
$('#table_detail_special .tableSpecialdelAll').on('click', function() {
    specialChecks = []
    var tagCheck = $(this).prop("checked")
    $.each($('#table_detail_special tbody input[type=checkbox]'), function(index, item) {
            // console.log(tagCheck)
            $(item).prop('checked', tagCheck)
        })
        // if(tagCheck){

    selectSpecialCheck()
        // }
        // if(tagCheck){
        //     selectSpecialCheck()
        // }

})


$('#table_detail_special').on('change', 'input[type=checkbox][name=specialCheck]', function() {
    var checkBtn = $('#table_detail_special tbody input[type=checkbox]:checked').length;
    var checkAllBtn = $('#table_detail_special .table-special-one').length;
    // console.log(checkBtn, checkAllBtn)
    if (checkBtn == checkAllBtn) {
        $('#table_detail_special .tableSpecialdelAll').prop("checked", true)
    } else {
        $('#table_detail_special .tableSpecialdelAll').prop("checked", false)
    }
    var indId = $('#table_detail_special th[name=tagDetailVassetiId]').index();
    var nowTagVassitId = $(this).parents('tr').find('th:eq(' + indId + ')').text();
    if ($(this).prop("checked")) {
        // 记录特殊区域选中的数据

        var flag = false;
        for (var i in specialChecks) {
            if (i == nowTagVassitId) {
                flag = true;
                // console.log('error')
            }
        }
        if (!flag) {
            specialChecks.push(nowTagVassitId)
        }
        // console.log(specialChecks)

    } else {

        for (var i = 0; i < specialChecks.length; i++) {
            // console.log(specialChecks[i])
            if (specialChecks[i] == nowTagVassitId) {
                specialChecks.splice(i, 1);
                break;
            }
        }
        // console.log(specialChecks)
    }

})

$('#tables-all-del').on('click', function() {

    var shortVassetiId = specialChecks
    // console.log(window.OPTIONS['AREA005x1x1'].resourceInfo, "window.OPTIONS['AREA005x1x1'].resourceInfo")
    layer.msg('确定要删除?', {
        time: 0, //不自动关闭,
        btn: ['确定', '取消'],
        yes: function(index) {
            layer.close(index);
             var indId = $('#table_detail_special th[name=tagDetailVassetiId]').index();
                        
            $.each(specialChecks,function(index,item){
                console.log(item)
                shortVassetiId.push($(item).parents('tr').find('th:eq('+indId+')').html())
            }) 


            // console.log(shortVassetiId, ' shortVassetiId')

            var shortPostJson = {
                template_type: "AREA",
                template_no: 1,
                area_no: nowAreaPos,
                collist_id: collist1.id,
                column_id: collist2.id,
                subcolumn_id: collist3.id,
                vasseti_id: shortVassetiId,
                templateDetailsId: TemplateDetailsId
            }
            // console.log(shortPostJson)
            $.ajax({
                url: '/template_type/data/area/subcolumn/delete',
                type: 'POST',
                cache: false,
                dataType: 'json',
                data: shortPostJson,
                success: function(data) {
                    // console.log(data)
                    if (data.status == 'success') {
                        layer.alert(data.content, { icon: 1 });

                        // 重新渲染2级栏目下模板
                         $.each($('#table_detail_special tbody input[type=checkbox]:checked'),function(index,item){
                            console.log(item);
                            $(item).parents('tr').remove();
                        }) 
                        newPageAreaChange();
                        // 再次渲染当前栏目下数据信息
                        fillNowPageArea5(null, store.get('current_area'), function() {
                            refreshDataTable()
                        })
                        $('.tableSpecialdelAll input[name=check-all][type=checkbox]').prop('checked', false)


                        // $('#table_detail_common').hide();
                        // $('#table_detail_special').show();
                    } else {
                        layer.msg(data.content, { icon: 2 });
                    }

                },
                error: function() {
                    layer.msg("异常！");
                }
            });

        }
    })

})



/*
 * selectSpecialCheck 特殊区域全部选择删除
 */
function selectSpecialCheck() {
    console.log(specialChecks)
    $.each($('#table_detail_special tbody tr'), function(ind, item) {
        console.log(item,'item-----selectSpecialCheck',ind)
        var indItem = $(item).index();
        var itemCheck = $(item).find('input[type=checkbox][name=specialCheck]')
        specialChecks.push($(item).children('th:eq(2)').text())

    })
    console.log(specialChecks,'----2')
     if(specialChecks.length>=1){
        var flag = false
        for(var i in specialChecks){
            // if(i == assertId){
            // flag = true;
            // return;
            // }
        }
        // if(flag){
        //     specialChecks.push(assertId)
        // }
    }else{
        // specialChecks.push(assertId)
    }
    console.log(specialChecks) 
}
$("#impic_upload").change(function() {
    if (!nowAreaPos) return;
    var shortJson = {
        template_type: window.OPTIONS[nowAreaPos].areaType,
        template_no: window.OPTIONS[nowAreaPos].areaId,
        area_no: nowAreaPos,
        template_details_id: TemplateDetailsId,
        tag_no: tagNo,
        subcolumn_id: collist3.id,
        // img:new FormData($('#uploadForm')[0])
    }
    // console.log(shortJson)
    $("#chat_form").ajaxSubmit({
        type: 'post', //请求类型
        url: '/operation/content_templates/area/upload_img', //该php中可接收$_FILES数组
        data: shortJson,
        beforeSubmit: function() {
            //提交前的操作
            // $('input[name=template_type]').value(window.OPTIONS[nowAreaPos].areaType);
            // $('input[template_details_id]').value(TemplateDetailsId)
        },
        success: function(data) {
            //操作成功后
            // $("#image").val(data.imgsrc);
            // console.log(data)
            layer.msg(data.content);
            $('#' + nowAreaPos).find('img').eq(tagNo - 1).attr({ "src": data.path })
        },
        resetForm: true, //操作完成后是否重置表单
        dataType: 'json' //返回数据格式
    });
});
$('.shandowMark').hide();
